<template>
  <div class="container" style="width:99%;margin-top:-25px;">
    <!-- 查询条件 -->
    <div class="query-box">
      <el-form :model="queryBox" status-icon ref="queryBox">
        <el-row>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户类型</div>
              <el-select clearable v-model="queryBox.customerType" filterable>
                <el-option
                  v-for="item in student_type_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户来源</div>
              <el-select filterable clearable v-model="queryBox.customerSource" placeholder="请选择">
                <el-option
                  v-for="item in student_data_from_options"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                >{{item.value}}</el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">客户进展</div>
              <el-form-item @change="student_progress_change">
                <el-select clearable v-model="queryBox.customerProgress" placeholder="请选择">
                  <el-option
                    v-for="item in student_progress_options"
                    :key="item.key"
                    :label="item.value"
                    :value="item.key"
                  >{{item.value}}</el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="4">
            <el-form-item label prop="customerNumber">
              <el-input v-model="queryBox.customerNumber" placeholder="客户编号">
                <template slot="prepend">客户编号</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label prop="name">
              <el-input v-model="queryBox.agentName" placeholder="意向客户">
                <template slot="prepend">意向客户</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4">
            <div class="depart-box">
              <div class="slect-title">所属销售</div>
              <el-autocomplete
                v-model="queryBox.assigner"
                :fetch-suggestions="querySearchAsync2"
                placeholder="请输入内容"
                @select="handleSelect2"
              ></el-autocomplete>
            </div>
          </el-col>
          <el-col :span="7">
            <div class="depart-box">
              <div class="slect-title">创建时间</div>
              <el-date-picker
                v-model="createDate"
                type="daterange"
                :start-placeholder="'开始时间'"
                :end-placeholder="'结束时间'"
                range-separator="至"
                :default-time="['00:00:00', '23:59:59']"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </div>
          </el-col>
          <el-col :span="10">
              <el-row class="area">
                <el-col :span="4">
                  <span class="city-title">所在地区：</span>
                </el-col>
                <el-col :span="16" style="margin-left:-1px">
                    <el-form-item label="" prop="area">                
                      <el-cascader
                      clearable
                      size="large"
                      :options="options"
                      v-model="selectedOptions"
                      @change="handleChange"
                      >
                      </el-cascader>
                  </el-form-item>
                </el-col>
              </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="7">
            <div class="depart-box" style="margin-bottom:20px;">
              <div class="slect-title" style="width:150px;">最新分配时间</div>
              <el-date-picker
                v-model="allocationDate"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div class="from-btns">
        <kt-button
          :label="$t('action.reset')"
          perms="true"
          type="primary"
          @click="reset('queryBox')"
        />
        <kt-button
          :label="$t('action.search')"
          perms="true"
          type="primary"
          @click="search"
        />
      </div>
    </div>
    <!-- 批量删除按钮 -->
    <div class="add-btns fl">
      <kt-button
        :label="$t('action.batchdistribution')"
        :disabled="this.selections.length===0"
        perms="customerdistribution:xuecoo:batchdistribution"
        type="primary"
        @click="handlebatchdistribution"
      />

      <kt-button
        :label="$t('action.batchDelete')"
        perms="customerdistribution:xuecoo:delete"
        :size="size"
        type="danger"
        @click="handleBatchDelete"
        :disabled="this.selections.length===0"
        style="float:left;"
      />
    </div>
    <div class="fr">
      <kt-button
        :label="$t('action.download-tmpl')"
        type="primary"
        perms="customerdistribution:xuecoo:download"
        @click="downloadTmpl"
      ></kt-button>
      <kt-button
        :label="$t('action.batchimport')"
        type="primary"
        perms="customerdistribution:xuecoo:batchimport"
        @click="customerManagerImport"
      ></kt-button>
      <kt-button
        :label="$t('action.add-user')"
        type="primary"
        perms="customerdistribution:xuecoo:add"
        @click="handleNewADD"
      ></kt-button>
    </div>
    <!--表格内容栏-->
    <Crm-table
      @selectionChange="selectionChange"
      class="table-width"
      CustomerdistributionXuecoo
      width="400"
      permsSee="customerdistribution:xuecoo:see"
      permsEdit="customerdistribution:xuecoo:edit" 
      :data="pageResult"
      :columns="columns"
      :loading='loading'
      @findPage="findPage"
      @changeSwitch="changeSwitch"
      @handleEdit="handleEdit"
      @handleSee="handleSee"
    ></Crm-table>

    <!--批量分配-->
    <div class="batchdistribution-pop">
      <el-dialog
        :visible.sync="batchdistribution"
        @close="$emit('update:batchdistribution', false)"
        width="30%"
      >
      <el-row>
        <el-col :span="24">
          <span class="batchdistribution-pop-tit">客户分配</span>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <span class="checked-person">已经选择{{selections.length}}位客户</span>
        </el-col>
      </el-row>
        <el-form :inline="true" :model="addstuformData" class="demo-form-inline">
          <el-row>
            <el-col :span="24" v-if="aa">
              <el-row>
                <el-col :span="6">
                  <span class="tit">人员选择：</span>
                </el-col>
                <el-col :span="18">
                  <el-select clearable v-model="deptuseroptionValue" placeholder="请选择"  @change="deptuserchange">
                    <el-option
                    v-for="item in users"
                    :key="item.value"
                    :label="item.realName"
                    :value="item.id">
                    </el-option>
                </el-select>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="batchdistribution = false">取 消</el-button>
          <el-button type="primary" v-if="aa" @click="batchdistributionsubmituser">确 定</el-button>
        </span>
      </el-dialog>
    </div>
    <!--导入-->
    <el-dialog :title="'批量导入'" width="30%" :visible.sync="uploadOem" :close-on-click-modal="false">
      <el-form :model="form">
        <el-form-item>
          <el-upload
            ref="uploadExcel"
            :action="uploadUrl"
            :limit="limitNum"
            :auto-upload="false"
            accept=".xls"
            :before-upload="beforeUploadFile"
            :on-change="fileChange"
            :on-exceed="exceedFile"
            :on-success="handleSuccess"
            :on-error="handleError"
            :file-list="fileList"
            :on-remove="handleRemove"
          >
            <el-button size="small" plain>选择文件上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传xls(Excel97-2004)文件</div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="uploadOem = false">{{$t('action.cancel')}}</el-button>
        <el-button :size="size" type="primary" @click.native="uploadFile">{{$t('立即上传')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import CrmTable from "@/views/Core/CrmTable";
import CrmSwitch from "@/views/Core/CrmSwitch";
import { regionDataPlus } from "element-china-area-data";
import { CodeToText } from "element-china-area-data";
import { baseUrl } from "@/utils/global";
import Cookies from "js-cookie"
import axios from "axios";
export default {
  name: "Xuecoo",
  components: {
    PopupTreeInput,
    CrmTable,
    KtButton,
    CrmSwitch
  },
  data() {
    return {
      aa: true,
      checkedPeson: 0,
      size: "small",
      // filters: {
      //   name: ""
      // },
      // 查询条件
      student_data_from_options: [
        {
          label: " ",
          key: " "
        }
      ],
      //   地区
      options: regionDataPlus,
      selectedOptions: [],
      student_type_options: [],
      student_progress_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_data_from_type_options: [
        {
          label: " ",
          key: " "
        }
      ],
      isopen: [
        {
          value: "解锁",
          label: "1"
        },
        {
          value: "锁定",
          label: "2"
        }
      ],
      queryBox: {
        belongType: "2",
        customerSource: "",
        customerProgress: "",
        allotType: "",
        lockStatus: "",
        assigner: ""
      },
      trackingDate: "",
      createDate: "",
      width: 200,
      columns: [
        { type: "index", label: "序号", minWidth: 50 },
        { prop: "createDate", label: "创建时间", minWidth: 140 },
        { prop: "agentName", label: "意向客户", minWidth: 80 },
        { prop: "customerSource", label: "客户来源", minWidth: 100 },
        { prop: "customerType", label: "客户类型", minWidth: 120 },
        { prop: "customerProgress", label: "客户进展", minWidth: 70 },
        { prop: "diqu", label: "地区", minWidth: 190 },
        { prop: "providerTeacher", label: "销售人员", minWidth: 100 },
        { prop: "demo2", label: "最新跟进时间", minWidth: 140 },
        { prop: "allocationDate", sortable: "true", label: "最新分配时间", minWidth: 140 },
        { prop: "customerNumber", label: "客户编号", minWidth: 150 }
      ],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {
        content: []
      },
      operation: true, // true:新增, false:编辑
      batchdistribution: false, //显示批量分配弹窗
      customerownership: false, //显示客户归属弹窗
      uploadOem: false, //文件上传
      limitNum: 1, //上传最大个数
      form: {
        file: ""
      },
      fileList: [],
      uploadUrl: baseUrl + "/file/upload", //文件上传地址
      downloadTmplUrl: baseUrl + "/template/studentImportTemplate.xlsx", //模板下载地址
      selectionsLength: "",
      deptTreeProps: {
        label: "name",
        children: "children"
      },
      roles: [],
      selections: [], //选中列表集合
      ids: [], //分配ID集合
      ids2: [],
      deptData: [], //部门树
      deptTree: {
        label: "deptName",
        children: "children"
      },
      deptinputValue: "",
      // 划分方式
      deptmodeoptions: [
        {
          label: "分配至部门",
          value: "11"
        },
        {
          label: "分配至个人",
          value: "9"
        }
      ],
      deptmodeoptionsValue: "",
      submitID: "",
      deptId:  Cookies.get('threeLevelDeptId'),
      userID: "", //人员ID
      deptuseroption: [], //部门用户
      deptuseroptionValue: "",
      branchcenter: [], //分中心下拉
      branchcenterValue: "",
      branchcenterValueID: "",
      branchcenterCodeValue: "", //分中心编码
      addstuformData: {},
      userName: "",
      deptLevel3: "",
      users: [],
      loading: false, // 加载标识
       allocationDate: "",
    };
  },
  methods: {
    // 搜索
    search() {
      this.loading=true
      this.queryBox.province = this.selectedOptions[0];
      this.queryBox.city = this.selectedOptions[1];
      this.queryBox.area = this.selectedOptions[2];
      this.queryBox.createStartDate = this.createDate[0];
      this.queryBox.createStopDate = this.createDate[1];
      this.queryBox.trackingStartDate = this.trackingDate[0];
      this.queryBox.trackingStopDate = this.trackingDate[1];
      this.pageRequest.pageNum = 1;
      if (this.allocationDate != null) {
        this.queryBox.allocationStartDate = this.allocationDate[0];
        this.queryBox.allocationStopDate = this.allocationDate[1];
      } else {
        this.queryBox.allocationStartDate = "";
        this.queryBox.allocationStopDate = "";
      }
      this.findPage(null);
    },
    handleChange(value) {
      console.log(value);
    },
    // 获取分页数据
    findPage: function(data) {
      if (data !== null) {
        this.loading=true
        this.pageRequest = data.pageRequest;
      }
      this.queryBox.pageSize = this.pageRequest.pageSize;
      this.queryBox.pageNum = this.pageRequest.pageNum;
      this.pageRequest = Object.assign({}, this.pageRequest, this.queryBox, {
        belongType: 2
      });
      let belongType = "2"; //部门
      this.$api.agent
        .investmentQueryXuecoo(this.pageRequest)
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            let content = {
              content: res.investmentInfos,
              totalSize: res.total
            };
            this.pageResult = content;
            this.pageResult.content.forEach(item => {
              if ((item.province == null && item.city == null) ||
                (item.province == "null" && item.city == "null")) {
                item.diqu = "";
              } else {
                item.diqu = CodeToText[item.province] + CodeToText[item.city]+ CodeToText[item.area];
              }
              this.student_data_from_options.forEach(type_item => {
                if (type_item.key == item.dataFrom) {
                  item.laiyuan = type_item.value;
                }
              });
              this.student_progress_options.forEach(progress_item => {
                if (progress_item.key == item.progress) {
                  item.getprogress = progress_item.value;
                }
              });
            });
            this.loading=false
          }
        })
        .then(data != null ? data.callback : "");
    },
    // 加载用户角色信息
    // findUserRoles: function() {
    //   this.$api.role.findAll().then(res => {
    //     // 加载角色集合
    //     this.roles = res.data;
    //   });
    // },
    // 重置
    reset(queryBox) {
      this.$refs.queryBox.resetFields();
      this.queryBox.customerType = "";
      this.queryBox.customerSource = "";
      this.queryBox.customerProgress = "";
      this.queryBox.providerAgent = "";
      this.queryBox.trackingStartDate = "";
      this.queryBox.trackingStopDate = "";
      this.queryBox.dataFromType = "";
      this.queryBox.lockStatus = "";
      this.queryBox.assigner = "";
      this.queryBox.allotType = "";
      this.queryBox.importDepartment = "";
      this.queryBox.agentName = "";
      this.queryBox.province = "";
      this.queryBox.city = "";
      this.queryBox.area = "";
      this.createDate = "";
      this.trackingDate = "";
      this.queryBox.createStartDate = "";
      this.queryBox.createStopDate = "";
      this.selectedOptions=[]
      this.pageRequest.pageNum = 1;
      this.allocationDate = "";
      this.queryBox.allocationStartDate = "";
      this.queryBox.allocationStopDate = "";
      this.findPage(null);
    },
    // 批量分配
    handlebatchdistribution(params) {
      this.batchdistribution = true;
      this.ids = [];
      let idstu = this.selections.map(item => item.id);
      // this.dataFormAdd = Object.assign({}, params.row);
      this.ids = idstu;
      this.deptuseroptionValue = "";
      this.deptuseroption = "";
    },
    // 获取三级部门数据
    get_dept_data() {
      this.$api.dropdown.deptLevel3({ deptType: 1 }).then(res => {
        this.deptData = res.departmentInfoList;
      });
    },
    //获取下拉列表
    findDown: function() {
      this.$api.dropdown.deptLevel3().then(res => {
        this.deptLevel3 = res.departmentInfoList;
      });
      // 获取人员
      this.$api.dropdown.users({ userType: 3 }).then(res => {
        this.Allusers = res.userInfoList;
      });
    },
    // 选择人员
    deptuserchange(value) {
      this.userID = value;
    },
    //三级部门下面员工集合
    findUsersDown: function(value) {
      // let threeId=JSON.parse(Cookies.get("threeLevelDeptId"))
      let threeId=Cookies.get("threeLevelDeptId")
      if(threeId=='null'){
        this.$api.dropdown.users({userType:3,accountStatus:1,isControlResource:1}).then(res =>{
          this.users=res.userInfoList
        })
      }else{
        this.$api.dropdown.users({userType:3,threeLevelDeptId:threeId,accountStatus:1,isControlResource:1}).then(res =>{
          this.users=res.userInfoList
        })
      }
      // this.$api.dropdown
      //   .users({ userType: 3, threeLevelDeptId: this.deptId,accountStatus:1})
      //   .then(res => {
      //     this.users = res.userInfoList;
      //   });
    },
    // 获取部门用户
    get_dept_user() {
      this.$api.student.queryUserList({ id: this.deptId }).then(res => {
        this.deptuseroption = res.userInfoList;
      });
    },
    // 批量调整归属中心
    handleCustomerOwnership() {
      this.customerownership = true;
      this.ids2 = [];
      let idstu2 = this.selections.map(item => item.id);
      // this.dataFormAdd = Object.assign({}, params.row);
      this.ids2 = idstu2;
    },
    // 获取分中心
    get_branchcenter() {
      this.$api.dropdown.branchcenter().then(res => {
        this.branchcenter = res.branchCenterInfoList;
      });
    },
    branchcenterChange(value) {
      this.branchcenterValue = value.name;
      this.branchcenterCodeValue = value.code;
      this.branchcenterValueID = value.id;
    },
    // 提交归属分中心
    branchcenterSubmit() {
      console.log(this.ids);
      this.$api.student
        .studentBelongTo({
          branchCenterId: this.branchcenterValueID,
          listStudentId: this.ids2
        })
        .then(res => {
          if (res.result === 1) {
            this.$message({
              message: res.msg,
              type: "success"
            });
            this.customerownership = false;
            this.findPage(null);
          } else {
            this.$message({
              message: res.msg,
              type: "error"
            });
          }
        });
    },
    // 批量删除
    handleBatchDelete() {
      this.ids2 = [];
      let idstu2 = this.selections.map(item => item.id);
      // this.dataFormAdd = Object.assign({}, params.row);
      this.ids2 = idstu2;
      let customerIds = this.ids2.join(",");
      this.$confirm("确认删除"+this.selections.length+"个客户吗？", "提示", {}).then(() => {
        this.editLoading = true;
        this.$api.agent
          .investmentDelete({
            customerIds: customerIds,
            deleteType: 2
          })
          .then(res => {
            this.$message({ message: res.msg, type: "success" });
            this.findPage(null);
          });
      });
    },
    // 查看客户档案
    handleSee: function(params) {
      this.dataForm = Object.assign({}, params.row);
      // console.log(params.row)
      this.$router.push({
        path: "/Customerfile/XuecooAgent",
        query: {
          id: this.dataForm.id
        }
      });
    },
    // 新增客户
    handleNewADD: function() {
      this.$router.push({
        path: "/Customerfile/AddXuecoo",
        query: {
          belongType: "2"
        }
      });
    },
    selectionChange: function(params) {
      let selectionsLength = params.selections.length;
      this.selections = selections.selections;
    },
    // 获取选中的表格数据
    selectionChange: function(selections) {
      this.selections = selections.selections;
    },
    // 修改客户档案
    handleEdit: function(params) {
      this.dataForm = Object.assign({}, params.row);
      this.$router.push({
        path: "/Customerfile/EditXuecoo",
        query: {
          id: this.dataForm.id
        }
      });
    },
    // 菜单树选中
    handleOptionClick() {},
    // 获取来源
    get_investment_customer_from() {
      this.student_data_from_options=JSON.parse(localStorage.getItem('investmentSource'))
    },
    // 进展
    get_investment_customer_progress() {
      this.student_progress_options=JSON.parse(localStorage.getItem('investmentProgress'))
    },
    student_progress_change(value) {
      this.queryBox.student_progressValue = value.toString();
    },
    // 获取类型
    get_investment_customer_type() {
      this.student_type_options=JSON.parse(localStorage.getItem('investmentType'))
    },
    // 获取方式
    get_student_data_from_type() {
      this.student_data_from_type_options=JSON.parse(localStorage.getItem('investmentDataFromType'))
    },
    student_parent_type_change(value) {
      this.info.studentInfoDetail.studentInfoAttr.parentType = value.toString();
    },
    // 获取部门数据
    get_dept_data() {
      this.$api.dropdown.deptLevel3().then(res => {
        this.tableData = res.departmentInfoList;
        this.deptData = res.departmentInfoList;
        this.date = res.departmentInfoList;
        this.date.forEach(item => {
          item.text = item.deptName;
          item.value = item.deptName;
        });
      });
    },
    // 批量分配提交
    batchdistributionsubmituser() {
      console.log(this.deptId)
       let customerIds = this.ids.join(",");
      this.$api.agent
        .investmentAllotCustomer({
          customerIds: customerIds,
          belongType: 1,
          threeDeptId: this.deptId, //部门ID
          assigner: this.userID
        })
        .then(res => {
          if (res.result === 1) {
            this.$message({
              message: res.msg,
              type: "success"
            });
            this.batchdistribution = false;
            this.findPage(null);
          } else {
            this.$message({
              message: res.msg,
              type: "success"
            });
          }
        });
    },
    // 解锁锁定
    changeSwitch: function(data) {
      this.$api.agent
        .investmentLock({
          customerId: data.row.id
        })
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else
            this.$message({
              message: res.msg,
              type: "success"
            });
        });
    },
    // 批量导入
    customerManagerImport: function() {
      this.uploadOem = true;
      if(this.form.file!=''){
        this.$refs.uploadExcel.clearFiles()
        this.form.file=''
      } 
    },
    // 文件超出个数限制时的钩子
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: "警告",
        message: `只能选择 ${
          this.limitNum
        } 个文件，当前共选择了 ${files.length + fileList.length} 个`
      });
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      this.form.file = file.raw;
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
      let size = file.size / 1024 / 1024;
      if ((extension !== "xlsx") & "xls") {
        this.$notify.warning({
          title: "警告",
          message: `只能上传Excel97-2004（即后缀是.xls）的文件`
        });
      }
    },
    // 文件上传成功时的钩子
    handleSuccess(res, file, fileList) {
      this.$refs.uploadExcel.clearFiles();
      this.form.file=''
      this.$notify.success({
        title: "成功",
       message: `文件上传成功,数据处理中,稍后在我的消息中查看！`
      });
    },
    // 文件上传失败时的钩子
    handleError(err, file, fileList) {
      this.$notify.error({
        title: "错误",
        message: `文件上传失败`
      });
    },
    uploadFile() {
      let formData = new FormData();
      formData.append("file", this.form.file);
      axios
        .post(this.uploadUrl, formData, {
          "Content-Type": "multipart/form-data"
        })
        .then(res => {
          if (res.data.result == 1) {
            this.handleSuccess();
            let path = res.data.fileUrl;
            console.log(path);
            this.$api.agent
              .importStudyKooInfo({ path: path, importFrom: 2 }) //importFrom  1: 我的客户导入; 2: 部门导入（客户分配）; 3:  资源划分导入   4: 客户管理导入
              .then(res => {
                if(res.result==1){
                  this.$message({
                    message:res.msg,
                    type:'success'
                  })
                }else{
                  this.$message({
                    message:res.msg,
                    type:'error'
                  })
                }
                this.uploadOem = false;
                this.findPage(null);
              });
          } else {
            this.handleError();
          }
        });
    },

    // 删除上传列表操作
    handleRemove(file, fileList) {
      this.form.file=''
    },

    // 下载模板
    downloadTmpl() {
      this.getAgentTempl();
    },
    // 分中心远程搜索
    querySearchAsync(queryString, callback) {
      let restaurants = [{}];
      let results = "";
      this.$api.dropdown.branchcenter().then(res => {
        for (let i of res.branchCenterInfoList) {
          i.value = i.name; //将想要展示的数据作为value
        }
        restaurants = res.branchCenterInfoList;
        results = queryString
          ? restaurants.filter(this.createFilter(queryString))
          : restaurants;
        callback(results);
      });
    },
    createFilter(queryString) {
      return restaurant => {
        return (
          restaurant.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    handleSelect(item) {
      this.queryBox.providerAgent = item.id;
    },
    // 销售人员远程搜索
    querySearchAsync2(queryString, callback) {
      let restaurants = [{}];
      let results = "";
      let threeId=JSON.parse(Cookies.get("threeLevelDeptId"))
      if(threeId==null){
        this.$api.dropdown.users({ userType: 3,deptType:2}).then(res => {
          for (let i of res.userInfoList) {
            i.value = i.realName; //将想要展示的数据作为value
          }
          restaurants = res.userInfoList;
          results = queryString
            ? restaurants.filter(this.createFilter2(queryString))
            : restaurants;
          callback(results);
        });
      }else{
        this.$api.dropdown.users({ userType: 3,deptType:2,threeLevelDeptId:this.deptId}).then(res => {
          for (let i of res.userInfoList) {
            i.value = i.realName; //将想要展示的数据作为value
          }
          restaurants = res.userInfoList;
          results = queryString
            ? restaurants.filter(this.createFilter2(queryString))
            : restaurants;
          callback(results);
        });
      }
    },
    createFilter2(queryString) {
      return restaurant => {
        return (
          restaurant.realName
            .toLowerCase()
            .indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    handleSelect2(item) {
      console.log(item);
      // this.queryBox.belongTo = item.id;
    },
    // 获取销售姓名
    get_sale_name() {
      this.$api.dropdown.users({ userType: 3 }).then(res => {
        this.belongTo = res.userInfoList;
      });
    }
  },
  mounted() {
    this.get_investment_customer_from();
    this.get_investment_customer_progress();
    this.get_dept_data();
    this.get_branchcenter();
    this.get_investment_customer_type();
    this.get_student_data_from_type();
    this.get_sale_name();
    this.findUsersDown();
  }
};
</script>
<style >
@import url("../../assets/queryBox.css");
</style>
<style lang='scss' scoped>
.checked-person {
  font-weight: 500;
  display: inline-block;
  text-align: center;
  margin: 3% 0 3% 0;
}
.batchdistribution-pop-tit{
  font-size: 20px;
  font-weight: bold;
  display: inline-block;
  color: #303133;
}
.demo-form-inline{
  .el-select{
    width: 100%;
  }
  .tit{
    margin-top:10%;
    display: inline-block;
    margin-bottom: 2%;
  }
  width: 90%;
  margin:0 auto;
}
.batchdistribution-pop .el-row .el-col {
  margin-left: 0;
}
.el-dialog__wrapper .el-form-item__content{
  margin-left: 0;
}
</style>
<style lang='scss'>
.batchdistribution-pop .el-dialog__header{
  padding: 0 0 0 0 !important;
}
</style>


